package com.fudan.cfg.base;

import java.util.HashMap;
import java.util.Map;

public class RunProperties {

	private Map<String,Object> configs;

	public RunProperties() {
		this.configs = new HashMap<>();
	}


	public String getStringConfigOrDefault(String key,String defaultValue) {
		Object value = null;
		String[] keys = key.split("[.]");

		for (String t : keys) {
			if(value == null) {
				value = configs.get(t);
			}else {
				value = ((Map<String,Object>)value).get(t);
			}
			if(value == null) {
				return defaultValue;
			}
		}

		if(value == null) {
			return defaultValue;
		}
		return String.valueOf(value);
	}

	public Map<String,Object> getConfigMap(String key) {
		return (Map<String, Object>) configs.get(key);
	}

	public Map<String,Object> getConfigs() {
		return configs;
	}

	public void setConfigs(Map<String,Object> configs) {
		this.configs = configs;
	}

	public void loadConfig(Map<String,Object> propMap) {
		configs.putAll(propMap);
	}
}
